//
//  KKEmptyView.swift
//  JGTProject
//
//  Created by ifly on 2017/8/7.
//  Copyright © 2017年 szy. All rights reserved.
//

import UIKit
import SnapKit


typealias kkEmpyAction = () -> Void

class KKEmptyView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    private var kkImgView = UIButton()
    private var textLbl = UILabel()
    var kkAction:kkEmpyAction?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        self.backgroundColor = UIColor.white
        
        self.addSubview(kkImgView)
        
        let tapOne = UITapGestureRecognizer(target: self, action: #selector(KKEmptyView.btnAction))
        tapOne.numberOfTapsRequired = 1
        tapOne.numberOfTouchesRequired = 1
        self.addGestureRecognizer(tapOne)
        
        kkImgView.setImage(UIImage.init(named: "loading"), for: .normal)
        kkImgView.setImage(UIImage.init(named: "loading"), for: .highlighted)
        
        self.addSubview(textLbl)
        textLbl.textAlignment = .center;
        textLbl.font = UIFont.boldSystemFont(ofSize: 16)
        textLbl.textColor = UIColor.gray
        
        kkImgView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(-60)
            make.size.equalTo(CGSize(width: 120, height: 120))
        }
        
        textLbl.snp.makeConstraints { (make) in
            make.top.equalTo(kkImgView.snp.bottom).offset(5)
            make.left.equalTo(self).offset(40)
            make.right.equalTo(self.snp.right).offset(-40)
            make.height.equalTo(40)
        }
    }
    
    func setImg(_ img:UIImage, withText text:String) -> Void {
        
        kkImgView.setImage(img, for: .normal)
        kkImgView.setImage(img, for: .highlighted)
        textLbl.text = text
        
    }

    @objc func btnAction(){
        if (self.kkAction != nil) {
            self.kkAction!()
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
